package io.gitee.tooleek.lock.spring.boot.core.key.strategy;

import java.lang.reflect.Method;

import io.gitee.tooleek.lock.spring.boot.core.key.LockKey;
import io.gitee.tooleek.lock.spring.boot.core.key.LockKey.Builder;
import io.gitee.tooleek.lock.spring.boot.core.key.RedisLockKey;
import io.gitee.tooleek.lock.spring.boot.core.key.ZookeeperLockKey;
import io.gitee.tooleek.lock.spring.boot.enumeration.LockScheme;
import io.gitee.tooleek.lock.spring.boot.exception.KeyBuilderException;

public class ClassKeyStrategy extends KeyStrategy {

	public ClassKeyStrategy(LockScheme scheme,String className, String methodName, Method realMethod, Object[] args) {
		super(scheme,className, methodName, realMethod, args);
	}

	@Override
	public Builder generateBuilder() throws KeyBuilderException {
		Builder keyBuilder;
		if(scheme==LockScheme.REDIS) {
			keyBuilder = RedisLockKey.newRedisKeyBuilder();
		}else {
			keyBuilder = ZookeeperLockKey.newZookeeperKeyBuilder();
		}
		keyBuilder.appendKey(wrapKeyTag(new StringBuilder(getSimpleClassName()).append(".").append(methodName).toString()));
		
		return keyBuilder;
	}

}
